﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


using FlexiGridHelper;
using System.Data;
using System.Web.Script.Serialization;
namespace Golf.WebUI.HttpHandler.Customer
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary> 
    public class Golf_User : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            JavaScriptSerializer js = new JavaScriptSerializer();
            Golf.BLL.Golf_User bll = new Golf.BLL.Golf_User();
            List<Golf.Model.Golf_User> list = new List<Golf.Model.Golf_User>();
            //实例化页面信息类，获取页面传来的参数。该类是FlexiGridHelper中定义的类，封装了很多功能需要的数据
            PageView pageView = new PageView(context);
            //获取分页后的数据集
            DataSet ds = bll.GetList(pageView.PageSize, pageView.PageIndex, "0=0");
            //构建表格
            DataTable dt = new DataTable();
            //构建列
            //注意：第一列必须是数据库的主键列  
            DataColumn dc0 = new DataColumn("Id", typeof(string));
            DataColumn dc1 = new DataColumn("UserType", typeof(string));
            DataColumn dc2 = new DataColumn("FristName", typeof(string));
            DataColumn dc3 = new DataColumn("Email", typeof(string));
            DataColumn dc4 = new DataColumn("State", typeof(string));
            DataColumn dc5 = new DataColumn("RegisterTime", typeof(string));
            DataColumn dc6 = new DataColumn("LoginTime", typeof(string));
            DataColumn dc7 = new DataColumn("Endtime", typeof(string));
            DataColumn dc8 = new DataColumn("LastName", typeof(string));
            DataColumn dc9 = new DataColumn("PassWord", typeof(string));
            DataColumn dc10 = new DataColumn("action", typeof(string));//操作
            //把构建的列添加到数据表中
            dt.Columns.AddRange(new DataColumn[] { dc0, dc1, dc2, dc8, dc9, dc3, dc4, dc5, dc6, dc7, dc10 });//这里有个顺序的哟 
            list = bll.DataTableToList(ds.Tables[0]);//获取第一张表的数据  就是数据库中的数据
            //填充数据
            foreach (var item in list)
            {
                //新建行，注意是dt.NewRow();而不是new DataRow();
                DataRow dr = dt.NewRow();
                dr["ID"] = item.Id;
                dr["UserType"] = item.UserType;
                dr["FristName"] = item.FristName;
                dr["Email"] = item.Email;
                dr["State"] = item.State == 1 ? "有效" : "无效";
                dr["RegisterTime"] = item.RegisterTime;
                dr["LoginTime"] = item.LoginTime;
                dr["Endtime"] = item.Endtime;
                dr["LastName"] = item.LastName;
                dr["PassWord"] = item.PassWord;

                dt.Rows.Add(dr);
            }
            //调用FlexiGrid数据格式转换方法
            context.Response.Write(js.Serialize(new GetDataHelper().GetFlexiGridData(pageView, dt, (int)ds.Tables[1].Rows[0][0])));//ds.Tables[1].Rows[0][0] 这里是数据库表的记录行数  是第二张表的 在dao类中的最后方法中
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
